from appium import webdriver
import time


def get_device_resolution():
    # 配置 Appium 的 Desired Capabilities
    desired_caps = {
        "platformName": "Android",
        "deviceName": "YourDeviceName",  # 例如: "Android Emulator"
        "appPackage": "com.android.settings",  # 你可以使用任何已安装的应用包名
        "appActivity": ".Settings",  # 你可以使用任何已安装的应用活动名
        "automationName": "UiAutomator2"  # 使用 UiAutomator2 自动化引擎
    }

    # 启动 Appium 会话
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    try:
        # 等待设备准备好
        time.sleep(5)

        # 获取设备分辨率
        window_size = driver.get_window_size()
        width = window_size['width']
        height = window_size['height']
        print(f"设备分辨率: {width}x{height}")
    finally:
        # 关闭会话
        driver.quit()


if __name__ == "__main__":
    get_device_resolution()